/**
 * amis v2.4.0
 * Copyright 2018-2022 baidu
 */

import { __extends, __rest, __assign, __decorate, __metadata } from 'tslib';
import React from 'react';
import { isPureVariable, resolveVariableAndFilter, autobind, FormItem } from 'amis-core';
import { withRemoteConfig, ConditionBuilder } from 'amis-ui';

var ConditionBuilderControl = /** @class */ (function (_super) {
    __extends(ConditionBuilderControl, _super);
    function ConditionBuilderControl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ConditionBuilderControl.prototype.renderEtrValue = function (schema, data) {
        return this.props.render('inline', Object.assign(schema, { label: false }), data);
    };
    ConditionBuilderControl.prototype.renderPickerIcon = function () {
        var _a = this.props, render = _a.render, pickerIcon = _a.pickerIcon;
        return pickerIcon ? render('picker-icon', pickerIcon) : undefined;
    };
    ConditionBuilderControl.prototype.render = function () {
        var _a = this.props, className = _a.className, cx = _a.classnames; _a.pickerIcon; var rest = __rest(_a, ["className", "classnames", "pickerIcon"]);
        // 处理一下formula类型值的变量列表
        var formula = this.props.formula ? __assign({}, this.props.formula) : undefined;
        if (formula && formula.variables && isPureVariable(formula.variables)) {
            // 如果 variables 是 ${xxx} 这种形式，将其处理成实际的值
            formula.variables = resolveVariableAndFilter(formula.variables, this.props.data, '| raw');
        }
        return (React.createElement("div", { className: cx("ConditionBuilderControl", className) },
            React.createElement(ConditionBuilderWithRemoteOptions, __assign({ renderEtrValue: this.renderEtrValue, pickerIcon: this.renderPickerIcon() }, rest, { formula: formula }))));
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object, Object]),
        __metadata("design:returntype", void 0)
    ], ConditionBuilderControl.prototype, "renderEtrValue", null);
    return ConditionBuilderControl;
}(React.PureComponent));
var ConditionBuilderWithRemoteOptions = withRemoteConfig({
    adaptor: function (data) { return data.fields || data; }
})(/** @class */ (function (_super) {
    __extends(class_1, _super);
    function class_1() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    class_1.prototype.render = function () {
        var _a = this.props, loading = _a.loading, config = _a.config; _a.deferLoad; var disabled = _a.disabled, renderEtrValue = _a.renderEtrValue, rest = __rest(_a, ["loading", "config", "deferLoad", "disabled", "renderEtrValue"]);
        return (React.createElement(ConditionBuilder, __assign({}, rest, { fields: config || rest.fields || [], disabled: disabled || loading, renderEtrValue: renderEtrValue })));
    };
    return class_1;
}(React.Component)));
/** @class */ ((function (_super) {
    __extends(ConditionBuilderRenderer, _super);
    function ConditionBuilderRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ConditionBuilderRenderer = __decorate([
        FormItem({
            type: 'condition-builder',
            strictMode: false
        })
    ], ConditionBuilderRenderer);
    return ConditionBuilderRenderer;
})(ConditionBuilderControl));

export { ConditionBuilderControl as default };
